$(function ()
{
    //设置指定面板展开
    $('#layout').layout('expand', 'north');

    //设置开始时间
    setStartTime();

    var datagrid = $("#dg").datagrid(
        {
            url : "../../api/dd_findAllOrder?checkState=1",
            //isField : "testnum",
            method : "get",
            width : 1000,
            height : 550,
            rownumbers : true, //显示行号
            singleSelect : true,//只支持单选
            toolbar : '#tc',//设置工具栏的id
            pagination : true, //显示分页
            pageSize : 10, //分页大小
            pageList : [5, 10, 15, 20], //每页的个数
            beforePageText : '第',
            afterPageText : '页    共 {pages} 页',
            displayMsg : '当前显示 {from} - {to} 条记录   共 {total} 条记录',
            fit : true, //自动补全
            fitColumns : true,
            title : "",
            columns : [[//每个列具体内容
                    {
                        field : 'ck',
                        checkbox : true
                    },
                     {
                        field : 'orderNo',
                        title : '订单编码',
                        width : 100,
                        align : 'center'
                       
                    },
                    {
                        field : 'productLine',
                        title : '线体名称',
                        width : 150,
                        align : 'center'
                        
                    },
                    {
                        field : 'productLineNo',
                        title : '线体编码',
                        width : 100,
                        align : 'center'
                    },
                    {
                        field : 'productDescription',
                        title : '型号描述',
                        width : 100,
                        align : 'center'
                    },
                    {
                        field : 'planCount',
                        title : '计划数量',
                        width : 100,
                        align : 'center'
                    },
                     {
                        field : 'checkCount',
                        title : '应抽数量',
                        width : 100,
                        align : 'center'
                    },
                    {
                        field : 'checkDate',
                        title : '计划时间',
                        width : 100,
                        align : 'center',
                        formatter:function(val,row){
                            var now = new Date(val);
                            return now.format("yyyy-MM-dd hh:mm:ss");
                        }
                    },
                    {
                        field : 'checkState',
                        title : '抽样检测状态',
                        width : 130,
                        align : 'center',
                        formatter:function(value , record , index)
                        {
                            if(value==0){
                                return '<span style=color:red; >待检测</span>' ;
                            }else if( value ==1){
                                return '<span style=color:green; >检测中</span>' ; 
                            }else if( value ==2){
                                return '<span style=color:green; >整改中</span>' ; 
                            }else if( value ==3){
                                return '<span style=color:green; >检测完成</span>' ; 
                            }else if( value ==4){
                                return '<span style=color:green; >报告审核</span>' ; 
                            }else if(value ==5){
                                return '<span style=color:green; >报告审批</span>' ; 
                            }
                            else{
                                return '<span style=color:green; >订单结束</span>' ; 
                            }
                        }
                    },
                ]],
        }
        );

    //查看订单
    $("#viewOrder").click(function ()
    {

        var rows = datagrid.datagrid('getSelections');

        if (rows.length <= 0)
        {
            $.messager.alert('警告', '您没有选择', 'warning');
        }
        else if (rows.length > 1)
        {
            $.messager.alert('警告', '不支持批量接收', 'warning');
        }
        else
        {
            var index = datagrid.datagrid('getRowIndex', datagrid.datagrid('getSelected'));
            var row1 = datagrid.datagrid('getData').rows[index];
            window.open("../../menu/ExperimentManage/btn_ViewOrderOfReportRelease?testnum=" + row1.testnum);
            // window.location.href="../../menu/OrderManage/btn_ViewOrderOfReportRelease?testnum="+row1.testnum;
        }

    }
    );

   
    //录入结果
    $("#inputResult").click(function ()
    {
        //获取选中的行
        var rows = datagrid.datagrid('getSelections');
        if (rows.length <= 0)
        {
            $.messager.alert({
                        title:'警告',
                        msg:'您没有选择',
                        icon: 'error',
                        width: 200,
                        top:200
                    });
        }
        else
        {
            const orderNo=rows[0].orderNo;//订单编码
            window.location.href="../../menu_nj/ExperimentManage/ExperimentOrderInput?orderNo="+orderNo;
        }
    }
    );

    //整改订单
    $("#modifyOrder").click(function ()
    {

        var rows = datagrid.datagrid('getSelections');

        if (rows.length <= 0)
        {
            $.messager.alert('警告', '您没有选择', 'warning');
        }
        else if (rows.length > 1)
        {
            $.messager.alert('警告', '不支持批量录入', 'warning');
        }
        else
        {
            var index = datagrid.datagrid('getRowIndex', datagrid.datagrid('getSelected'));
            var row1 = datagrid.datagrid('getData').rows[index];
            if (row1.status == 2||row1.status == 3)
            {
                $.messager.alert("警告", "订单正在整改中！", "warning");
            }
            else if (row1.status == 4)
            {
                $.messager.alert("警告", "订单已经整改成功！", "warning");
            }
            else if (row1.status == 5)
            {
                $.messager.alert("警告", "订单整改失败！", "warning");
            }
            else if (row1.status == 1)
            {
                window.location.href = "../../menu_nj/RectificationManagement/CreatingRefromOrder?orderNo=" + row1.workuserMordercode;
            }
        }

    }
    );
}
);

//整体模糊查询
function searchOrderData()
{

    //产品型号编码
    var WORK_OPERATIONOUTMAINITEMCODE = $('#WORK_OPERATIONOUTMAINITEMCODE').textbox('getValue');
    //订单编码
    var WORKUSER_MORDERCODE = $('#WORKUSER_MORDERCODE').textbox('getValue');
    //检测状态
    var STATUS = $('#STATUS').textbox('getValue');
    //线体名称
    var WORKUSER_LINENAME = $('#WORKUSER_LINENAME').textbox('getValue');
    //开始时间
    var startTime = $('#startTime').datetimebox('getValue');
    //结束时间
    var endTime = $('#endTime').datetimebox('getValue');

    //reload形式加载模糊查询,成功
    $('#dg').datagrid('reload', '../../api/nj_getOrderData?productNo=' + WORK_OPERATIONOUTMAINITEMCODE + '&orderNo=' +
        WORKUSER_MORDERCODE + '&lineName=' + WORKUSER_LINENAME + '&status' + STATUS + '&startTime=' + startTime + '&endTime=' + endTime);

    //插入系统日志
    var pagetitle = "临时订单";
    var page = "menu/OrderManage/TempOrder";
    var operation = "2";
    var detail = "查询临时订单";
    //InsertSysLog(pagetitle,page,operation,userrealname,userno,detail);

}
